package com.wcar.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcar.common.entity.ProductType;
import com.wcar.common.vo.Result;
import com.wcar.product.dao.ProductTypeDao;
import com.wcar.product.service.ProductTypeService;
import com.wcar.product.vo.ProductTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductTypeServiceImpl implements ProductTypeService {
    @Autowired
    private ProductTypeDao productTypeDao;
    @Override
    public Result<List<ProductType>> selectAllProductType() {
        List<ProductType> productTypes = productTypeDao.selectList(null);
        return new Result<>(200,"查询商品类型成功",productTypes);
    }

    @Override
    public Result<Page<ProductType>> selectProductType(ProductTypeVo productTypeVo) {
        Page<ProductType> page = new Page<>(productTypeVo.getCurrentPage(),productTypeVo.getPageSize());
        QueryWrapper<ProductType> wrapper = new QueryWrapper<>();
        if (productTypeVo.getName() != null){
            wrapper.like("name",productTypeVo.getName());
        }
        Page<ProductType> list = productTypeDao.selectPage(page, wrapper);
        return new Result<>(200,"查询商品类型成功",list);
    }

    @Override
    public Result<ProductType> updateProductType(ProductType productType) {
        int i = productTypeDao.updateById(productType);
        return new Result<>(200,"修改商品类型成功",null);
    }

    @Override
    public Result<ProductType> deleteProductTypeById(Integer commentId) {
        int i = productTypeDao.deleteById(commentId);
        return new Result<>(200,"删除商品类型成功",null);
    }

    @Override
    public Result<ProductType> insertProductType(ProductType productType) {
        int insert = productTypeDao.insert(productType);
        return new Result<>(200,"添加商品类型成功",null);
    }

    @Override
    public Result<Boolean> updateIseditByChangeId(ProductType commentId) {
        if(commentId.getIsedit().equals("1")){
            commentId.setIsedit("0");
        }else {
            commentId.setIsedit("1");
        }
        return new Result<>(200,"修改成功",null);
    }
}
